{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dedicated-seafood",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "List(3, 3, 3, 3)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "defined \u001b[32mfunction\u001b[39m \u001b[36mlistOfDuplicates\u001b[39m"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def listOfDuplicates[A](x:A,length:Int):List[A] =  {\n",
    "    if (length <1 ) Nil\n",
    "    else x :: listOfDuplicates(x,length - 1)\n",
    "}\n",
    "\n",
    "println(listOfDuplicates(3,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "quick-miniature",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "List(La, La, La, La, La, La, La, La)\n"
     ]
    }
   ],
   "source": [
    "println(listOfDuplicates(\"La\",8))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "coupled-scout",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[36mb\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"m\"\u001b[39m"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "//类型推断\n",
    "\n",
    "val b = \"m\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "chinese-property",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defined \u001b[32mfunction\u001b[39m \u001b[36msquareOf\u001b[39m"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def squareOf(x:Int) = x*x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "fewer-genius",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defined \u001b[32mfunction\u001b[39m \u001b[36mfac\u001b[39m"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def fac(n :Int): Int = if (n == 0) 1 else n*fac(n - 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "rotary-appreciation",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defined \u001b[32mclass\u001b[39m \u001b[36mmp\u001b[39m\r\n",
       "\u001b[36mp\u001b[39m: \u001b[32mmp\u001b[39m[\u001b[32mInt\u001b[39m, \u001b[32mString\u001b[39m] = \u001b[33mmp\u001b[39m(\u001b[32m1\u001b[39m, \u001b[32m\"scala\"\u001b[39m)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "case class mp[A,B](x:A,y:B)\n",
    "val p = mp(1,\"scala\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "marine-particular",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defined \u001b[32mfunction\u001b[39m \u001b[36mid\u001b[39m\r\n",
       "\u001b[36mq\u001b[39m: \u001b[32mInt\u001b[39m = \u001b[32m1\u001b[39m"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def id[T](x:T) = x\n",
    "val q = id(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "beautiful-defensive",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[36mres8\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mInt\u001b[39m] = \u001b[33mList\u001b[39m(\u001b[32m2\u001b[39m, \u001b[32m4\u001b[39m, \u001b[32m6\u001b[39m)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Seq(1,2,3).map(x =>x * 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "western-cause",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Scala",
   "language": "scala",
   "name": "scala"
  },
  "language_info": {
   "codemirror_mode": "text/x-scala",
   "file_extension": ".scala",
   "mimetype": "text/x-scala",
   "name": "scala",
   "nbconvert_exporter": "script",
   "version": "2.11.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
